package example.audio.track.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import example.audio.track.Track;
import example.audio.track.repository.TrackRepository;
import example.audio.track.service.TrackService;

@Service
public class TrackManager implements TrackService {
	@Autowired
	private TrackRepository trackRepository;
	
	@Override
	@Transactional
	public Track addTrack(Track track) {
		track.setAdded(new Date());
		return trackRepository.addTrack(track);
	}

	@Override
	@Transactional(readOnly=true)
	public List<Track> getAllTracks() {
		return trackRepository.getAllTracks();
	}

	@Override
	@Transactional(readOnly=true)
	public Track getTrackById(Integer id) {
		return trackRepository.getTrackById(id);
	}

	@Override
	@Transactional
	public Track updateTrack(Track track) {
		track.setUpdated(new Date());
		return trackRepository.updateTrack(track);
	}

	@Override
	@Transactional(readOnly=true)
	public List<Track> getConditionalTracks(Map<String, Object> params) {
		return trackRepository.getConditionalTracks(params);
	}

}
